/**
 * Created by yaohuan on 2018/4/11 0011.
 */
define(function () {

    var self;

    var Fwsl = app.Module.extend({

        init: function () {
            self = this;
            self.mData = {};
            self.searchData = {
                date: '',
                type: 2
            };
            self._super({
                _tag: 'p_fwsl', // key, 对象放进pageModule
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true,//自动加载刷新控件
                _readyBefore:function () {

                }
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1', 'scroll2'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/fwsl/getServiceOrderList",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    MMRD020: goods.type.replace('scroll', ''),
                    MMRDDOCDATE: self.searchData.date
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        goods.data.pushArray(data.data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: self._refreshIndex == 0 ? '无未受理服务单...' : '无已受理服务单...'
                        });
                    }else
                        app.toast(result.data.message)
                }
            });
        },
        _ready:function(){
            Vue.component('fwsl-listitem', {
                template: app.getByid(doc, 'item-template'),
                props: {
                    model: Array
                },
                methods: {
                    showDetail: function (item) {
                        app.openPage({
                            src: "fwsl/fwsl-info.html",
                            argsKey: 'fwslinfo_page',
                            args: item
                        });
                    }
                }
            });

            new Vue({
                el: doc.getElementById('searchs'),
                data: {
                    md: self.searchData
                },
                methods: {
                    today: function () {
                        // 格式化日期
                        self.searchData.date = new Date().Format('yyyy-MM-dd');
                        self.searchData.type = 0;
                        self._refresh();
                    },
                    tomorrow: function () {
                        self.searchData.type = 1;
                        // 格式化日期 and 天+1
                        self.searchData.date = new Date().addDays(1, 'yyyy-MM-dd');
                        self._refresh();
                    },
                    all: function () {
                        self.searchData.date = '';
                        self.searchData.type = 2;
                        self._refresh();
                    }
                }
            });
        },
        _lazy:function () {
            this._super();
            doc.getElementById('search_date').addEventListener('change', function () {
                self.mData.status = 3;
                self._refresh();
                return false;
            });
        }
    });

    return new Fwsl();

});